package no.sachmuld.methodcombination.api;

import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 *
 */
public abstract class DefaultTestTemplate {

    @Test
    public void shouldExecuteBehaviourDefaultStyle() throws Exception {
        List<Step> expected = Arrays.asList(Step.BEFORE_Y, Step.BEFORE_X, Step.AFTER_X, Step.AFTER_Y);
        final List<Step> actual = new ArrayList<>();

        Foo foo = createFoo();

        foo.with(new FooBehaviour() {
            @Override
            public void bar(MethodInvocation<Void> methodInvocation) {
                actual.add(Step.BEFORE_X);
                methodInvocation.proceed();
                actual.add(Step.AFTER_X);
            }
        });
        foo.with(new FooBehaviour() {
            @Override
            public void bar(MethodInvocation<Void> methodInvocation) {
                actual.add(Step.BEFORE_Y);
                methodInvocation.proceed();
                actual.add(Step.AFTER_Y);
            }
        });

        foo.bar();

        Assert.assertEquals(expected, actual);

    }

    static public enum Step {
        BEFORE_X, AFTER_X, BEFORE_Y, AFTER_Y
    }

    static public abstract class FooBehaviour {
        public void bar(MethodInvocation<Void> methodInvocation) {
            methodInvocation.proceed();
        }
    }

    static public abstract class Foo extends MethodCombinationSupport<FooBehaviour> {
        public abstract void bar();
    }

    protected abstract Foo createFoo();

}
